package com.woniu.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.service.AlarmMessageService;
import com.woniu.util.PageData;
import com.woniu.util.ResponseData;
import com.woniu.vo.AlarmMessageVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@RequestMapping("/alarm_msg")
@Slf4j
@CrossOrigin(origins = "*")
public class AlarmMssageController {
    @Autowired
    private AlarmMessageService alarmMessageService;

    /*
    * 分页查询
    * */
    @RequestMapping("/queryMsg")
    public ResponseData<PageData> queryMsg(@RequestBody PageData pageData){
        Page page = alarmMessageService.queryPage(pageData);
        log.info("分页参数: {},{}", page,page.getTotal());
        return ResponseData.ok(page);
    }

    /*
    * 查看
    * */
    @RequestMapping("/queryMsgByid")
    public ResponseData<AlarmMessageVo> queryMsgByid(Long id){
       log.info("id----->, {}", id);
        AlarmMessageVo alarmMessageVo = alarmMessageService.queryMsgByid(id);
    log.info("数据---->, {}", alarmMessageVo);
        return ResponseData.ok(alarmMessageVo);
    }

    /*
    * 更改状态
    * */
    @PostMapping("/updateStatus/{status}/{id}")
    public ResponseData updateStatus(@PathVariable("status") Integer status, @PathVariable("id") Long id){
        log.info("status----> {}, id-----> {}", status, id);
        alarmMessageService.updateStatus(status, id);

        return ResponseData.ok();
    }

    @RequestMapping("/getChargerMsg")
    public ResponseData getChargerMsg(@RequestParam("id") Long id){
        log.info("id---------------> {}", id);
        AlarmMessageVo msgVo = alarmMessageService.getChargerMsg(id);

        return ResponseData.ok(msgVo);
    }

    @GetMapping("/msgeExcel")
    public ResponseData<?> outDepartmentExcelTemplate(HttpServletResponse response) throws IOException {
        return alarmMessageService.outDepartmentExcelTemplate(response);
    }
}
